//
//  AppDelegate.swift
//  33web
//
//  Created by 宋海胜 on 2020/11/25.
//

import UIKit
import CallKit
import CoreTelephony
import IQKeyboardManagerSwift
#if DEBUG // 判断是否在测试环境下
let kWebUrl = "http://118.25.77.91:8001/#/"
#else
let kWebUrl = "http://124.70.188.151:9012/#/"
#endif



@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
//    var webVC = HSWebViewController(path: kWebUrl)


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        //设置用户授权显示通知
        if #available(iOS 10.0, *) {
            UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.badge,.carPlay,.sound], completionHandler: { (success, error) in
                print("通知授权" + (success ? "成功" : "失败"))
            })
        }
        
        window = UIWindow(frame: UIScreen.main.bounds)
        let naVC = UINavigationController(rootViewController: HSWebViewController(path: kWebUrl))
        window!.rootViewController = naVC
        window!.makeKeyAndVisible()

        
        // 强制关闭暗黑模式
        if #available(iOS 13.0, *) {
            self.window?.overrideUserInterfaceStyle = .light
        }
        #if DEBUG // 判断是否在测试环境下
        print("当前环境：DEBUG")
        #else
        print("当前环境：RELEASE")
        #endif
        return true
    }
    func networkAuthStatus(stateClosure: @escaping ((Bool) -> Void)) {
        let cellularData = CTCellularData()
        cellularData.cellularDataRestrictionDidUpdateNotifier = {(state) in
            if (state == .restricted) {
                //拒绝
                if let t = UserDefaults.standard.value(forKey: "isFirstInApp") as? Bool, !t {
                    //                    self.networkSettingAlert()
                }
                stateClosure(false)
            } else if (state == .notRestricted) {
                //允许
                stateClosure(true)
            } else {
                //未知
                if let t = UserDefaults.standard.value(forKey: "isFirstInApp") as? Bool, !t {
                    //                    self.unknownNetwork()
                }
                stateClosure(false)
            }
        }
    }
}


